/**
 * 表单模型
 */
 module.exports = (app) => {
    const { STRING, INTEGER,TEXT } = app.Sequelize
    const FormTemplate = app.model.define('form_template', {
      id: {
        type: INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      formName: {
        type: STRING,
        allowNull: false,
      },
      formCode: {
        type: STRING,
        allowNull: false,
      },
      formTemplate: {
        type: TEXT,
        allowNull: false,
      },
      delFlag: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
      },
      formDataId: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 1,
      },
    },{
        timestamps: false,
    })
  
    // 表关联的字段
    FormTemplate.associate = function () {
      // 一对一
      app.model.FormTemplate.belongsTo(app.model.FormData, {
        foreignKey: 'formDataId',
        targetKey: 'id',
        as: 'formdata',
      })
    }
  
    return FormTemplate
  }